<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div>
        <!-- 把处理过后的数据以及统计后的结果展示在这里 -->
    </div>
    <script>
        var str = '85872637471533203552943982';
        // Step1: 找出现最多的字符和次数
        // 使用数组储存数字出现次数
        var strNum = {}
        for (var i = 0; i < str.length; i++) {
            if (strNum[str[i]]) {
                strNum[str[i]]++;
            } else {
                strNum[str[i]] = 1;
            }
        }
        // console.log(strNum)
        // 遍历strNum获取value最大的key保存至result
        var result = { 'num': 0, 'count': 0 };
        for (var key1 in strNum) {
            if (strNum[key1] > result['count']) {
                result['num'] = key1;
                result['count'] = strNum[key1];
            }
        }

        // Step2：去除重复的数字
        var temp = [];
        for (var i = 0; i < str.length; i++) {
            if (temp.indexOf(str[i]) == -1) {
                temp.push(str[i]);
            }
        }

        // Step3：冒泡排序
        for (var i = 0; i < temp.length - 1; i++) {
            for (var j = 0; j < temp.length - 1; j++) {
                if (temp[j] > temp[j + 1]) {
                    var n = temp[j]
                    temp[j] = temp[j + 1]
                    temp[j + 1] = n
                }
            }
        }
        console.log("step1.出现最多的字符：" + result['num'] +
            "，次数：" + result['count']);
        console.log("step2.去重后:" + temp.join(""));
        console.log("step3.排序后得：" + temp.join(""));

        let div = document.querySelector('div')
        div.innerText = "step1.出现最多的字符：" + result['num'] +
            "，次数：" + result['count'] + "\n" +
            "step2.去重后:" + temp.join("") +"\n" +
                "step3.排序后得：" + temp.join("")

    </script>
</body>

</html>